package com.suxin.http.model;

import com.alibaba.nacos.common.constant.HttpHeaderConsts;
import lombok.Data;
import org.springframework.http.MediaType;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Tang
 * @classname Header
 * @description [  ]
 * @date 2023/3/3 14:27
 */
@Data
public class Header {

    private Map<String, String> header;

    public final static Header EMPTY = newInstance();

    public Header() {
        this.header = new HashMap<>();
    }

    public static Header newInstance() {
        return new Header();
    }

    public Header addParam(String key, String value) {
        this.header.put(key, value);
        return this;
    }

    public Header setContentType(String contentType) {
        this.header.put(HttpHeaderConsts.CONTENT_TYPE, contentType);
        return this;
    }

    public Header build() {
        return this;
    }

    public String get(String key) {
        return this.header.get(key);
    }

    public Header addAll(Map<String, String> header) {
        this.header.putAll(header);
        return this;
    }

    public void setOriginHeaders(Map<String, List<String>> headerFields) {
        for (String key : headerFields.keySet()) {
            this.header.put(key, headerFields.get(key).get(0));
        }
    }
}
